package com.learn.postprocessor.postprocessor;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;

/**
 *
 * @author daify
 * @date 2019-03-26 17:38
 **/
public class BeanFactoryPostProcessorTest implements 
                                          BeanFactoryPostProcessor, Ordered {
    @Override public void postProcessBeanFactory(
            ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("调用 BeanFactoryPostProcessorTest ...");
        System.out.println("容器中有 BeanDefinition 的个数：" + beanFactory.getBeanDefinitionCount());
        // 获取指定的 BeanDefinition
        BeanDefinition bd = beanFactory.getBeanDefinition("postProcessorTest");
        MutablePropertyValues pvs = bd.getPropertyValues();
        pvs.addPropertyValue("id",2);
        pvs.addPropertyValue("name","inClass");
    }

    @Override public int getOrder() {
        return 1;
    }
}
